<?php

namespace App\Http\Controllers\XhAdmin;

use App\Http\Controllers\Admin\BaseController;
use App\Repository\XhApi\PhonesRepository;
use Illuminate\Http\Request;

// 号码管理
class PhonesController extends BaseController
{
    private $repoist;

    public function __construct(PhonesRepository $repository)
    {
        $this->repoist = $repository;
    }


    public function index(Request $request)
    {
        $dataArr = $this->repoist->index($request->all(), $request->get('pageNum'), $request->get('pageSize'));

        if (1 == $request->get('pageNum') && is_array($dataArr)) {
            $dataArr['statusList'] = [0 => '上架', 1 => '下架'];
            //号码是否预约下单
            $dataArr['bookingList'] = [0 => '实付', 1 => '预约'];
            $dataArr['operatorTypeList'] = config('card.operatorType');
        }
        return $dataArr;
    }

    public function edit(Request $request)
    {
        if (!$request->get('id')) {
            return $this->returnMsg(1, '请传递id参数');
        }
        return $this->repoist->edit($request->all());
    }

    public function add(Request $request)
    {
        return $this->repoist->add($request->all());
    }

    public function del(Request $request, $id)
    {
        if (!$id) {
            return $this->returnMsg(1, '请传递参数');
        }
        return $this->repoist->del($id, $request->user->shop_id);
    }

    public function status(Request $request)
    {
        if (!$request->id) {
            return $this->returnMsg(1, '请传递参数');
        }
        return $this->repoist->unifiedUpdateStatus($request->id, $request->status, $request->user->shop_id);
    }
}
